package cn.itcalvin.stat.exam.controller;

import cn.itcalvin.stat.exam.pojo.req.ReqSearch;
import cn.itcalvin.stat.exam.pojo.resp.RespStatDetails;
import cn.itcalvin.stat.exam.pojo.vo.Message;
import cn.itcalvin.stat.exam.pojo.vo.MessageUtil;
import cn.itcalvin.stat.exam.service.StatUserService;
import lombok.val;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

@RestController
public class StatController {

    private List<Integer> getOrgIds(Integer type){
        if(type.equals(1555)){
            return Arrays.asList(1, 15,45,46,47);
        }else if(type.equals(1122)){
            return Arrays.asList(13);
        } else if(type.equals(1344)){
            return Arrays.asList(14);
        }else if(type.equals(1742)){
            return Arrays.asList(16);
        }else {
            return null;
        }
    }


    @Resource
    StatUserService statUserService;


    @PostMapping("/statOnly/exam/searchDetails")
    public Message<List<RespStatDetails>> searchDetails(@RequestBody @Valid ReqSearch reqSearch) {
        final val orgIds = getOrgIds(reqSearch.getType());
        if(orgIds == null){
            return MessageUtil.error("输入参数错误，请联系系统管理员");
        }
        reqSearch.setOrgIds(orgIds);
        final List<RespStatDetails> search = statUserService.searchDetails(reqSearch);
        return MessageUtil.success(search, (long) search.size());
    }

}
